package com.example.yoho.mvp.presenter;

import android.util.Log;

import com.example.lib_core.mvp.presenter.BasePresenter;
import com.example.yoho.mvp.contract.CommunityContract;
import com.example.yoho.mvp.model.entity.CommunityBean;

import org.json.JSONException;
import org.json.JSONObject;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class CommunityPresenter extends BasePresenter<CommunityContract.Model,CommunityContract.View> {


    int page=0;

    @Inject
    public CommunityPresenter() {
    }
    public void reuqestCommunityAll(){

        JSONObject CommunityJob = new JSONObject();
        try {
            CommunityJob.put("page","1");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mModel.CommunityModel(CommunityJob.toString())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<CommunityBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        disposables.add(d);
                    }

                    @Override
                    public void onNext(CommunityBean communityBean) {
                        Log.e("yskssss", "onNext: "+communityBean.getValues().size());
                        mView.showCommunity(communityBean);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.showToast("请求失败"+e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.hideDialog();
                    }
                });
    }
}
